var t = getApp();

Page({
    data: {
        showcccc: !1,
        inputs: "",
        good_page: 1,
        order_field: "",
        order_by: "",
        is_hot: 0,
        cid: "",
        debtId: ""
    },
    onLoad: function(t) {
        t.id && this.setData({
            id: t.id
        }), 1 == t.hot && this.setData({
            is_hot: t.hot
        }), t.cid && (this.setData({
            cid: t.cid
        }), wx.setNavigationBarTitle({
            title: "供应商店铺"
        })), t.debtCId && (this.setData({
            debtCId: t.debtCId,
            is_debt: !0
        }), wx.setNavigationBarTitle({
            title: "分类"
        })), t.debtId && this.setData({
            debtId: t.debtId
        }), t.debtSearch && (this.setData({
            is_debt: !0
        }), wx.setNavigationBarTitle({
            title: "搜索"
        })), console.log(t, "xxxxxxx"), this.getGoodsData();
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    goToDetail: function(t) {
        var a = t.currentTarget.dataset.id;
        this.data.debtId ? wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a + "&debtId=" + this.data.debtId
        }) : wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.current_page >= this.data.good_total_page || (this.setData({
            good_page: this.data.good_page + 1
        }), this.nexTgetGoodsData());
    },
    onShareAppMessage: function() {},
    classifyBolbtn: function() {
        this.data.showcccc ? this.setData({
            showcccc: !1
        }) : this.setData({
            showcccc: !0
        });
    },
    inpbtn: function(t) {
        var a = t.detail.value;
        this.setData({
            inputs: a
        });
    },
    search: function() {
        this.setData({
            good_page: 1
        }), this.getGoodsData();
    },
    toggle: function(t) {
        var a = "";
        switch (t.currentTarget.dataset.idx) {
          case 2:
            this.setData({
                hascolor: 2
            }), "2_2" == this.data.colorshow ? (this.setData({
                colorshow: "2_1"
            }), a = "show_sales", this.setData({
                order_field: a,
                order_by: "asc"
            })) : (this.setData({
                colorshow: "2_2"
            }), a = "show_sales", this.setData({
                order_field: a,
                order_by: "desc"
            }));
            break;

          case 3:
            this.setData({
                hascolor: 3
            }), "3_2" == this.data.colorshow ? (this.setData({
                colorshow: "3_1"
            }), a = "price", this.setData({
                order_field: a,
                order_by: "asc"
            })) : (this.setData({
                colorshow: "3_2"
            }), a = "price", this.setData({
                order_field: a,
                order_by: "desc"
            }));
            break;

          case 5:
            this.setData({
                hascolor: 5
            }), "5_2" == this.data.colorshow ? (this.setData({
                colorshow: "5_1"
            }), a = "id", this.setData({
                order_field: a,
                order_by: "asc"
            })) : (this.setData({
                colorshow: "5_2"
            }), a = "id", this.setData({
                order_field: a,
                order_by: "desc"
            }));
        }
        this.setData({
            good_page: 1
        }), this.getGoodsData();
    },
    tapUpper: function() {
        try {
            wx.navigateBack({
                delta: 1,
                success: function(t) {},
                fail: function(t) {
                    wx.reLaunch({
                        url: "/packageG/index/index"
                    });
                },
                complete: function(t) {}
            });
        } catch (t) {
            wx.reLaunch({
                url: "/packageG/index/index"
            });
        }
    },
    getGoodsData: function() {
        var a = this, e = "";
        this.data.is_debt ? (e = t.getNetAddresss("goods.goods.search-goods"), t._isTextEmpty(this.data.debtCId) || (e += "&search[category]=" + this.data.debtCId)) : (e = t.getNetAddresss("plugin.supplier.frontend.shop.index.search-goods"), 
        e += "&sid=" + this.data.id, t._isTextEmpty(this.data.cid) || (e += "&category_id=" + this.data.cid)), 
        e += "&page=" + this.data.good_page, e += "&order_field=" + this.data.order_field, 
        e += "&order_by=" + this.data.order_by, e += "&search[keyword]=".concat(this.data.inputs || ""), 
        1 == this.data.is_hot && (e += "&is_hot=1"), t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result && a.setData({
                    goodsArr: e.data.data,
                    good_total_page: e.data.last_page,
                    current_page: e.data.current_page
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    nexTgetGoodsData: function() {
        var a = this, e = "";
        this.data.is_debt ? (e = t.getNetAddresss("goods.goods.search-goods"), t._isTextEmpty(this.data.debtCId) || (e += "&search[category]=" + this.data.debtCId)) : (e = t.getNetAddresss("plugin.supplier.frontend.shop.index.search-goods"), 
        e += "&sid=" + this.data.id, t._isTextEmpty(this.data.cid) || (e += "&category_id=" + this.data.cid)), 
        e += "&page=" + this.data.good_page, e += "&order_field=" + this.data.order_field, 
        e += "&order_by=" + this.data.order_by, e += "&search[keyword]=".concat(this.data.inputs || ""), 
        1 == this.data.is_hot && (e += "&is_hot=1"), t._getNetWork({
            url: e,
            success: function(t) {
                var e = t.data;
                1 == e.result && a.setData({
                    goodsArr: a.data.goodsArr.concat(e.data.data),
                    good_total_page: e.data.last_page,
                    current_page: e.data.current_page
                });
            },
            fail: function(t) {
                wx.showToast({
                    title: t.msg
                });
            }
        });
    }
});